const obj: { x: number; y?: string } = {
  x: 1,
}

type User = {
  firstName: string
  lastName?: string
}

const obj1: User = {
  firstName: 'Jack',
}

// 等同于
type User02 = {
  firstName: string
  lastName: string | undefined
}

const obj2: User02 = {
  firstName: 'Jet',
  lastName: undefined,
}

const user: { firstName: string; lastName?: string } = {
  firstName: 'foo',
}

if (user.lastName) {
  console.log(`my first name is ${user.firstName}, and my last name is ${user.lastName}`)
}

// 不等价
type A = { x: number; y?: string }
type B = { x: number; y: string | undefined }

const objA: A = { x: 1 }
// objB 必须显式写为 y: undefined
const objB: B = { x: 1, y: undefined }
